package com.mnurre.shopping.assistant;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;

public class ShoppingAssistantActivity extends Activity {

	private static final String TAG = "ShoppingAssistantActivity";
	
	private Button manageListsButton;
	private Button manageCategoriesButton;
	private Button manageProductsButton;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping_assistant);
        
        Log.d(TAG, "Getting the Button UI components.");
        manageListsButton = (Button)findViewById(R.id.manageListsButton);
        manageCategoriesButton = (Button)findViewById(R.id.manageCategoriesButton);
        manageProductsButton = (Button)findViewById(R.id.manageProductsButton);
        
        Log.d(TAG, "Adding the Button click handlers.");
        AddButtonHandlers();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
    	super.onCreateOptionsMenu(menu);
    	Log.d(TAG, "Creating the Options menu.");
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.menu_sa_activity, menu);
    	return true;
    }
    
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item){
    	Log.d(TAG, "Handling the menu item selected.");
    	switch(item.getItemId()){
    	case R.id.menu_sa_activity_tax_rate:
    		Log.d(TAG, "The Tax Rate button was pushed.");
    		editTaxRate();
    		break;
    	case R.id.menu_sa_activity_about:
    		Log.d(TAG, "The About button was pushed.");
    		showAbout();
    		break;
    	}
    	return super.onMenuItemSelected(featureId, item);
    }
    
    /*
     * Adds the event handlers for the buttons click events
     */
    private void AddButtonHandlers(){
    	
    	manageListsButton.setOnClickListener(
    			new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Start the manage lists activity
						showLists();
					}
				}
			);
    	
    	manageCategoriesButton.setOnClickListener(
    			new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Start the manage categories activity
						showCategories();
					}
				}
			);
    	
    	manageProductsButton.setOnClickListener(
    			new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Start the manage products activity
						showProducts();
					}
				}
			);
    }
    
    /*
     * Handles the menu's edit tax rate click event.
     */
    private void editTaxRate(){
    	Log.d(TAG, "Starting the EditTaxRateActivity.");
    	Intent intent = new Intent(this, EditTaxRateActivity.class);
    	startActivity(intent);
    }
    
    private void showAbout(){
    	Log.d(TAG, "Starting the --- about dialog activity ---.");
    }
    
    private void showLists(){
    	Log.d(TAG, "Launching the activity for showing lists.");
    	Intent intent = new Intent(this, ManageListsActivity.class);
    	startActivity(intent);
    }
    
    private void showCategories(){
    	Log.d(TAG, "Launching the activity for showing categories.");
    	Intent intent = new Intent(this, ManageCategoriesActivity.class);
    	startActivity(intent);
    }
    
    private void showProducts(){
    	Log.d(TAG, "Launching the activity for showing products.");
    	Intent intent = new Intent(this, ManageProductsActivity.class);
    	startActivity(intent);
    }
}
